//
//  NSDate+Calendar.m
//  RMNote
//
//  Created by lxf on 16/4/15.
//  Copyright © 2016年 lxf. All rights reserved.
//

#import "NSDate+Calendar.h"



@implementation NSDate (Calendar)

- (NSDateComponents *)getComsWithDate:(NSDate *)date{
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];//设置成中国阳历
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comps = [calendar components:unitFlags fromDate:date];
    return comps;
}

- (NSString *)year{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *year = [NSString stringWithFormat:@"%ld",(long)comps.year];
    
    return year;
}

- (NSString *)month{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *month = [NSString stringWithFormat:@"%ld",(long)comps.month];
    
    return month;
}

- (NSString *)weekDay{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *weekDay = [NSString stringWithFormat:@"%ld",(long)comps.weekday];
    
    return weekDay;
}

- (NSString *)day{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *day = [NSString stringWithFormat:@"%ld",(long)comps.day];
    
    return day;
}

- (NSString *)hour{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *hour = [NSString stringWithFormat:@"%ld",(long)comps.hour];
    
    return hour;
}

- (NSString *)minute{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *minute = [NSString stringWithFormat:@"%ld",(long)comps.minute];
    
    return minute;
}

- (NSString *)second{
    NSDateComponents *comps = [[NSDateComponents alloc]init];
    comps = [self getComsWithDate:self];
    NSString *second = [NSString stringWithFormat:@"%ld",(long)comps.second];
    
    return second;
}

//- (NSDate *)chinaDate{
//    NSDate *now = [NSDate date];
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT+0800"];
//    NSString *dateStr = [dateFormatter stringFromDate:now];
//    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
//    [dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    NSDate *chinaDate = [dateFormatter1 dateFromString:dateStr];
//    return chinaDate;
//}




@end
